<!--
 * @Descripttion: 
 * @Version: 
 * @Author: gaohj
 * @Date: 2023-01-12 16:06:40
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2023-01-12 16:21:01
-->
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        div{
            width: 200px;
            height: 200px;
            color:white;
            font-size: 20px;
            background-color: skyblue;
        }

        div.active{
            background-color: orange;
            width: 300px;
            height: 300px;
            color: pink;
            font-size: 30px;
        }
    </style>
</head>
<body>
    <div class="b1 b2 b3">卧榻之侧,岂容他人鼾睡</div>
    <button>按钮</button>
    <!-- <div class="a1 a2 a3"></div> -->

    <script>
        //1. 获取元素
        var div = document.querySelector('div');
        var btn = document.querySelector('button');
        // div.className = 'active';
        // div.className += ' a1 a2 a3';

        //2.classList

        // console.log(div.classList);  空伪数组 
        // div.classList.add('active');
        // div.classList.add('a1');
        // div.classList.add('a2');
        // div.classList.add('a3');


        // console.log(div.classList); //['b1', 'b2', 'b3', value: 'b1 b2 b3']
        // div.classList.remove('b2');

        btn.onclick = function(){
            div.classList.toggle('active');
        }


    </script>
</body>
</html>